/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package org.cip.esymons.tesoreria.be;

import java.io.Serializable;
import java.util.Date;
import java.util.List;
import javax.persistence.Basic;
import javax.persistence.CascadeType;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import javax.persistence.OneToMany;
import javax.persistence.Table;
import javax.persistence.Temporal;
import javax.persistence.TemporalType;
import javax.persistence.Transient;
import org.cip.esymons.eventos.be.Evento;
import org.cip.esymons.general.be.Empleado;

/**
 *
 * @author Gilmar Montoya
 */
@Entity
@Table(name = "tes_caja_chica")
//@NamedQueries({@NamedQuery(name = "CajaChica.findAll", query = "SELECT c FROM CajaChica c")})
public class CajaChica implements Serializable {

    private static final long serialVersionUID = 1L;
    @Id
    @GeneratedValue(strategy = GenerationType.IDENTITY)
    @Basic(optional = false)
    @Column(name = "cac_codigo", nullable = false)
    private Long cacCodigo;
    @Basic(optional = false)
    @Column(name = "cac_fecApertura", nullable = false)
    @Temporal(TemporalType.DATE)
    private Date cacFecApertura;
    @Column(name = "cac_fecCierre")
    @Temporal(TemporalType.DATE)
    private Date cacFecCierre;
    @Column(name = "cac_debe", precision = 20, scale = 4)
    private Double cacDebe;
    @Column(name = "cac_haber", precision = 20, scale = 4)
    private Double cacHaber;
    @Column(name = "cac_saldoAnterior", precision = 20, scale = 4)
    private Double cacSaldoAnterior=0.0;
    @Column(name = "cac_tipo")
    private EnumTipoCajaChica tipoCajaChica;
    @Column(name = "cac_estado")
    private EnumEstadoCajaChica estadoCajaChica;
    @Column(name="cac_transferidoSaldo")
    private boolean saldoTransferido;
    @JoinColumn(name = "fk_per_codigopna", referencedColumnName = "fk_per_codigopna", nullable = false)
    @ManyToOne(optional = false, fetch = FetchType.LAZY)
    private Empleado responsable;
    @OneToMany(cascade = CascadeType.ALL, mappedBy = "cajaChica", fetch = FetchType.LAZY)
    private List<DetCajaChica> ListaDetallesCajaChica;
    @JoinColumn(name = "eve_codigo", referencedColumnName = "eve_codigo")
    @ManyToOne(fetch = FetchType.LAZY)
    private Evento evento;
    @Transient
    private Double monto;

    public CajaChica() {
    }

    public CajaChica(Long cacCodigo) {
        this.cacCodigo = cacCodigo;
    }

    public CajaChica(Long cacCodigo, Date cacFecApertura, Date cacFecCierre) {
        this.cacCodigo = cacCodigo;
        this.cacFecApertura = cacFecApertura;
        this.cacFecCierre = cacFecCierre;
    }

    public Long getCacCodigo() {
        return cacCodigo;
    }

    public void setCacCodigo(Long cacCodigo) {
        this.cacCodigo = cacCodigo;
    }

    public Date getCacFecApertura() {
        return cacFecApertura;
    }

    public void setCacFecApertura(Date cacFecApertura) {
        this.cacFecApertura = cacFecApertura;
    }

    public Date getCacFecCierre() {
        return cacFecCierre;
    }

    public void setCacFecCierre(Date cacFecCierre) {
        this.cacFecCierre = cacFecCierre;
    }

    public Double getCacDebe() {
        return cacDebe;
    }

    public void setCacDebe(Double cacDebe) {
        this.cacDebe = cacDebe;
    }

    public Double getCacHaber() {
        return cacHaber;
    }

    public void setCacHaber(Double cacHaber) {
        this.cacHaber = cacHaber;
    }

    public Double getMontoRecibido(){

        try {
            return (cacDebe-cacSaldoAnterior);
        } catch (Exception e) {

            return 0.0;
        }
    }

    public List<DetCajaChica> getListaDetallesCajaChica() {
        return ListaDetallesCajaChica;

    }

    public void setListaDetallesCajaChica(List<DetCajaChica> ListaDetallesCajaChica) {
        this.ListaDetallesCajaChica = ListaDetallesCajaChica;
    }

    @Override
    public int hashCode() {
        int hash = 0;
        hash += (cacCodigo != null ? cacCodigo.hashCode() : 0);
        return hash;
    }

    @Override
    public boolean equals(Object object) {
        // TODO: Warning - this method won't work in the case the id fields are not set
        if (!(object instanceof CajaChica)) {
            return false;
        }
        CajaChica other = (CajaChica) object;
        if ((this.cacCodigo == null && other.cacCodigo != null) || (this.cacCodigo != null && !this.cacCodigo.equals(other.cacCodigo))) {
            return false;
        }
        return true;
    }

    @Override
    public String toString() {
        return "org.cip.esymons.tesoreria.be.CajaChica[cacCodigo=" + cacCodigo + "]";
    }

    /**
     * @return the empleado
     */
    public Empleado getResponsable() {
        return responsable;
    }

    /**
     * @param empleado the empleado to set
     */
    public void setResponsable(Empleado responsable) {
        this.responsable = responsable;
    }

    /**
     * @return the tipoCajaChica
     */
    public EnumTipoCajaChica getTipoCajaChica() {
        return tipoCajaChica;
    }

    /**
     * @param tipoCajaChica the tipoCajaChica to set
     */
    public void setTipoCajaChica(EnumTipoCajaChica tipoCajaChica) {
        this.tipoCajaChica = tipoCajaChica;
    }

    /**
     * @return the estadoCajaChica
     */
    public EnumEstadoCajaChica getEstadoCajaChica() {
        return estadoCajaChica;
    }

    /**
     * @param estadoCajaChica the estadoCajaChica to set
     */
    public void setEstadoCajaChica(EnumEstadoCajaChica estadoCajaChica) {
        this.estadoCajaChica = estadoCajaChica;
    }

    /**
     * @return the evento
     */
    public Evento getEvento() {
        return evento;
    }

    /**
     * @param evento the evento to set
     */
    public void setEvento(Evento evento) {
        this.evento = evento;
    }

    /**
     * @return the monto
     */
    public Double getMonto() {
        return monto;
    }

    /**
     * @param monto the monto to set
     */
    public void setMonto(Double monto) {
        this.monto = monto;
    }

    /**
     * @return the saldoTransferido
     */
    public boolean isSaldoTransferido() {
        return saldoTransferido;
    }

    /**
     * @param saldoTransferido the saldoTransferido to set
     */
    public void setSaldoTransferido(boolean saldoTransferido) {
        this.saldoTransferido = saldoTransferido;
    }

    /**
     * @return the cacSaldoAnterior
     */
    public Double getCacSaldoAnterior() {
        return cacSaldoAnterior;
    }

    /**
     * @param cacSaldoAnterior the cacSaldoAnterior to set
     */
    public void setCacSaldoAnterior(Double cacSaldoAnterior) {
        this.cacSaldoAnterior = cacSaldoAnterior;
    }
}
